<template>
  <el-row type="flex" justify="space-between" align="middle" style="height: 40px ; width:100%">
    <el-col>
      <!-- <span>{{ treeNode?treeNode.name:"江苏传智播客教育科技股份有限公司" }}</span> -->
      <strong v-if="isRoot"><i class="el-icon-office-building" /> <span>{{ treeNode.name }}</span></strong>
      <span v-else>{{ treeNode.name }}</span>

    </el-col>
    <el-col :span="6">
      <el-row type="flex" justify="end">
        <!-- 两个内容 -->
        <!-- <el-col>{{ treeNode?treeNode.message:'负责人' }}</el-col> -->
        <el-col>{{ treeNode.manager }}</el-col>
        <el-col>
          <!-- 下拉菜单 element -->
          <el-dropdown>
            <span>
              操作<i class="el-icon-arrow-down" />
            </span>
            <!-- 下拉菜单 -->
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item @click.native="addDepartment">添加子部门</el-dropdown-item>
              <el-dropdown-item v-if="!isRoot" @click.native="editDepartment">编辑部门</el-dropdown-item>
              <el-dropdown-item v-if="!isRoot" @click.native="delDepartment(treeNode.id)">删除部门</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </el-col>
      </el-row>
    </el-col>
  </el-row>
</template>

<script>
import { delDepartment } from '@/api/department'
export default {
  props: {
    // eslint-disable-next-line vue/require-default-prop
    treeNode: {
      type: Object,
      require: true
    },
    isRoot: {
      type: Boolean,
      default: false
    }
    // eslint-disable-next-line vue/require-default-prop

  },
  created() {
    // console.log(this.treeNode)

  },
  methods: {
    // 删除部门
    async delDepartment(id) {
      // console.log(id)
      await this.$confirm('是否删除部门?')
      await delDepartment(id)
      this.$message.success('删除成功')

      this.$emit('delFn')
    },

    // 新增部门
    addDepartment() {
      // const res = await addDepartment()
      console.log(this.treeNode)
      this.$emit('addDepartment', this.treeNode)
    },

    // 编辑部门
    editDepartment() {
      console.log(this.treeNode)
      this.$emit('editDepartment', this.treeNode)
    }
  }
}
</script>

<style>

</style>
